package it.unical.mat.aec.persistence;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionDB{
	
	private final String dbName="aec";
	
	public Connection getConnection() throws PersistanceException{
		String driver="com.mysql.jdbc.Driver";
		String dbUri= "jdbc:mysql://localhost:3306/"+dbName;;
		String userName = "admin";
		String password = "1234";
		driver = "com.mysql.jdbc.Driver";
		Connection connection = null;
		try {
		    Class.forName(driver);
		    connection = DriverManager.getConnection(dbUri, userName, password);
		}
		catch (ClassNotFoundException e) {
			throw new PersistanceException("Error: driver not found");
		}
		catch(SQLException e) {
			throw new PersistanceException("Erroe: connection failed");
		}
	   
		return connection;
	}

}
